#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
// priority_queue<int, vector<int>, less<int>> pq;

void solve()
{
    int w, f;
    scanf("%d%d", &w, &f);
    int n;
    cin >> n;
    vector<int> a(n);
    int s = 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
        s += a[i];
    }
    sort(a.begin(), a.end());
    int l = 1, r = s / min(w, f);
    auto check = [&](int m)
    {
        int x = m * w, y = m * f;
        if (x + y < s)
            return false;
        vector<bool> dp(x + 1);
        dp[0] = 1;
        for (auto k : a)
        {
            for (int i = x; i >= 0; i--)
            {
                if (i >= k)
                    dp[i] = dp[i] || dp[i - k];
            }
        }
        for (int i = max(0, s - y); i <= min(x, s); i++)
        {
            if (dp[i])
                return true;
        }
        return false;
    };
    while (l < r)
    {
        int mid = l + r >> 1;
        if (check(mid))
            r = mid;
        else
            l = mid + 1;
    }
    cout << l << endl;
}

signed main()
{
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}